<?php
/**
 * Created by PhpStorm.
 * User: william
 * Date: 16-8-31
 * Time: 下午2:44
 */
namespace V1;
class E_ProductChannel extends \ResourceClass {
    public $isActive = true;
    public $remark = '产品渠道';

    public function put(array $req, array $post, &$result)
    {
        if (!array_key_exists('id', $req) && !empty($req['id'])) {
            return 'require resource id';
        }
        if (!isset($req['uid'])) {
            return 'require user id ';
        }
        if (!isset($req['userType'])) {
            return 'require user type';
        }
        if (!isset($req['k']) || !isset($req['t'])) {
            return 'data error';
        }
        if (!array_key_exists('payload', $post)) {
            return 'require payload';
        }
        $enterprise_cls = \Biz\UserHandler::getById($req['userType'],$req['uid']);
        $enterprise_id = $enterprise_cls->getEnterpriseId();
        if (\Biz\UserHandler::checkAuth($req['userType'], $req['uid'],$enterprise_id,$req['id'] . $req['t'] . $post['payload'], $req['k']) == false) {
            return 'data illegal';
        }
        $data = base64_decode($post['payload']);
        @parse_str($data,$data);
        $update_data = array();
        if (isset($data['issale']) == false) {
            return 'require update column';
        }
        $update_data['issale'] = $data['issale'];
        $product_channel_handler = new \Biz\ProductHandler();
        $product_channel_cls = $product_channel_handler ->getProductChannelByProductChannelId($req['id']);
        $product_channel_cls ->setId($req['id'])
            ->setSaleStatus($update_data['issale']);
        try {
            $product_channel_handler ->updateProductChannelIssale($product_channel_cls);
        } catch (Exception $e) {
            return $e->getMessage();
        }
    }
}
